#ifndef _ADC3101_H
#define _ADC3101_H

//#include "ait_config.h"

#if 1
#define	I2C_PORT_MODE		(0x80000050)
#define	I2C_PORT_DATA		(0x80000051)


#define I2C_SCL             (0x1<<1)
#define I2C_SDA             (0x1<<2)

#define I2C_DELAY           100

#define I2C_HIGH            1
#define I2C_LOW             0

#define I2C_INPUT           0x0
#define I2C_OUTPUT          0x1

#define I2C_SET_OUT         0x0
#define I2C_CLEAR_OUT       0x1

#define ADC3101_PAGE_SELECT                          0x00
//Page 0
#define ADC3101_HARDWARE_RESET                       0x01
#define ADC3101_PLL_SETTING1                         0x04
#define ADC3101_PLL_SETTING2                         0x05//PLL P & R
#define ADC3101_PLL_SETTING3                         0x06//PLL J
#define ADC3101_PLL_SETTING4                         0x07//PLL D MSB
#define ADC3101_PLL_SETTING5                         0x08//PLL D LSB
#define ADC3101_PLL_SETTING8                         0x12//NADC
#define ADC3101_PLL_SETTING9                         0x13//MADC
#define ADC3101_PLL_SETTING10                        0x1A//MCLKOUT
#define ADC3101_INTERFACE_SETTING1                   0x1B
        #define I2S_FORMAT                           (0x0 << 6)
        #define DSP_FORMAT                           (0x1 << 6)
        #define RIGHT_JUSTIFIED_FORMAT               (0x2 << 6)
        #define LEFT_JUSTIFIED_FORMAT                (0x3 << 6)
        #define AUDIO_DATA_LENGTH_16                 (0x0 << 4)
        #define AUDIO_DATA_LENGTH_20                 (0x1 << 4)
        #define AUDIO_DATA_LENGTH_24                 (0x2 << 4)
        #define AUDIO_DATA_LENGTH_32                 (0x3 << 4)
        #define MASTER_MODE_ENABLE                   (0x08 | 0x04)
#define ADC3101_PLL_SETTING11                        0x1E//NBCLK
//Page 1
#define ADC3101_POWER_CONFIG                         0x01
#define ADC3101_LDO_CONFIG                           0x02

#define ADC3101_I2C_DEV_ADDR						 0x1B

#define	AUDIO_INIT_MICIN 	0x01   ///<Initialize the CODEC mic input
#define	AUDIO_INIT_LINEIN	0x02  ///<Initialize the CODEC line input
#define	AUDIO_INIT_IN		0x03      ///<Initialize the CODEC both line in and mic in
#define	AUDIO_INIT_OUT		0x04     ///<Initialize the CODEC output
#define	AUDIO_INIT_CUS		0x08     ///<Initialize the CODEC custom IO, reserved for special audio I/O
#define	AUDIO_UNINIT_MICIN	0x10 ///<Uninitialize the CODEC mic input
#define	AUDIO_UNINIT_LINEIN	0x20///<Uninitialize the CODEC line input
#define	AUDIO_UNINIT_IN		0x30    ///<Uninitialize the CODEC both line in and mic in
#define	AUDIO_UNINIT_OUT	0x40   ///<Uninitialize the CODEC output
#define	AUDIO_UNINIT_CUS	0x80    ///<Uninitialize the CODEC custom IO, reserved for special audio I/O
#define	AUDIO_INIT_OUT_LINEIN	0x100///<Initialize the CODEC output and line input

typedef enum _AUDIO_EXTCODEC_PATH
{
    AUDIO_EXT_SPK_OUT = 0,     ///< speaker output path
    AUDIO_EXT_HP_OUT,          ///< headphone output path
    AUDIO_EXT_MIC_IN,          ///< mic in path
    AUDIO_EXT_AUX_IN,          ///< AUX in path
    AUDIO_EXT_MIC_BYPASS_SPK,  ///< mic in bypass to speaker out
    AUDIO_EXT_MIC_BYPASS_HP,   ///< mic in bypass to headphone out
    AUDIO_EXT_AUX_BYPASS_SPK,  ///< AUX in bypass to speaker out
    AUDIO_EXT_AUX_BYPASS_HP,   ///< AUX in bypass to headphone out
    AUDIO_EXT_MIC_IN_SPK_OUT,  ///< mic in and speaker out
    AUDIO_EXT_MIC_IN_HP_OUT,   ///< mic in and headphone out
    AUDIO_EXT_AUX_IN_SPK_OUT,  ///< AUX in and speaker out
    AUDIO_EXT_AUX_IN_HP_OUT,   ///< AUX in and headphone out
    AUDIO_EXT_PATH_MAX
} AUDIO_EXTCODEC_PATH;

struct ADC3101_PLL_Setting {
	MMP_ULONG  samplerate;
	MMP_UBYTE  p_val;
	MMP_UBYTE  pll_j;
	MMP_USHORT pll_d;
	MMP_UBYTE  aosr;
	MMP_UBYTE  nadc;
	MMP_UBYTE  madc;
	MMP_UBYTE  bclk_N;
}; 

//extern void	InitExtDac(void);
void	InitExtMicIn(void);
void	PowerUpExtMicIn(void);
void	PowerDownExtMicIn(void);
//extern void	InitExtLineIn(void);
//extern void	PowerUpExtLineIn(void);
//extern void	PowerDownExtLineIn(void);
//extern MMP_BOOL	audioInitializer(MMP_USHORT cmd);

MMP_ERR MMPC_AudioExtCodec_SetPath(MMP_ULONG path);
MMP_ERR MMPC_AudioExtCodec_Init(MMP_ULONG samplerate, MMP_ULONG ulFixedMclkFreq);
MMP_ERR MMPC_AudioExtCodec_Uninit(void);
MMP_ERR MMPC_AudioExtCodec_SetSampleRate(MMP_ULONG ulSamplerate);
MMP_ERR MMPC_AudioExtCodec_SetMute(MMP_BOOL bMute);
MMP_ERR MMPC_AudioExtCodec_SetVolume(MMP_ULONG level);
MMP_ERR MMPC_AudioExtCodec_SetRecordVolume(MMP_LONG dB);//unit is 0.1dB, 0.5dB for each step, input range is 0~-415
void MMPF_InitTLV320ADC3101(MMP_ULONG samplerate);
void MMPF_PowerUpTLV320ADC3101(MMP_USHORT);
void MMPF_PowerDownTLV320ADC3101(void);
void MMPF_TLV320ADC3101VolumeControl(MMP_SHORT volume);
void MMPF_TLV320ADC3101_SetMute(MMP_UBYTE enable);
#endif
#endif